<?php
/*
 * Created on 20 mars 2009
 * Created by Ludovic Reenaers
 * lreenaers@hotmail.com
 */
 
 
 class User{
 	private $id;
 	private $nom;#60
 	private $prenom;#60
 	private $pseudo;#15
 	private $email;#255
 	private $rue;#60
 	private $numero;#6
 	private $boite;#6
 	private $cp;#20
 	private $ville;#60
 	private $pays;#100
 	private $Langue;# obj
 	private $ip;#15
 	private $ddn;#date
 	private $created;#timestamp
 	private $last_connected;#timestamp
 	private $pws_hash; #32
 	private $Profile;
 	private $active;
 	
 	function __construct($id) {
 		
 		if (is_int($id)){
 			if($id >= 0){
				$this->id=$id;
 			}else{
 				throw new FieldFormatException("id must be superior or equal to 0");
 			}
 		}else{
 			throw new FieldFormatException("id must be integer");
 		}
	}
	function setCreated($stamp){
		$this->created = $stamp;
	}
	function setPwsHash($pws,$confirm){
		
		if ($pws==$confirm){
			if(Validator::validateHash($pws)){
				$this->pws_hash  = $pws;
			}else{
				//throw new FieldFormatException("Password must be formated properly: minimum 6 char");
				throw new FieldFormatException("not a valid hash");
			}
		}else{
			throw new FieldFormatException("Password and confirmation must be equal");
		}
	}
	function setProfile($Profile){
		if($Profile instanceof Profile){
			$this->Profile = $Profile;
		}else{
			throw new FieldFormatException("Profile must be an instance of Profile bean");
		}
	}
	function setLastConnected($stamp){
		$this->last_connected = $stamp;
	}
	function setDdn($day,$month,$year){
		#ddn_str ex: 1977/01/22
		if(Validator::validateDate($day,$month,$year)){
			$this->ddn=$year."/".$month."/".$day;
		}else{
			throw new FieldFormatException("this is not a date.");
		}
	}
	function setActive($bool){
		$this->active = $bool;
	}
	function isActive(){
		return $this->active;
	}
	function setIp($ip){
		if(Validator::validateIp($ip)){
				$this->ip=$ip;
		}else{
			throw new FieldFormatException("this is not an IP.");
		}
	}
	function setPays($pays){
		if(is_string($pays)){
			if(str_replace(" ","",$pays) != ""){
				if(strlen($pays) > 0 and strlen($pays) < 101){
					$this->pays  =$pays;
				}else{
					throw new FieldFormatException("pays length could be 1 to 100 char");
				}
			}else{
				throw new FieldFormatException("pays could not be empty string");	
			}
		}else{
			throw new FieldFormatException("pays must be a string");
		}
	}
	function setVille($ville){
		if(is_string($ville)){
			
			if(str_replace(" ","",$ville) != ""){
				if(strlen($ville) > 0 and strlen($ville) < 61){
					$this->ville  =$ville;
				}else{
					throw new FieldFormatException("ville length could be 1 to 60 char");
				}
			}else{
				throw new FieldFormatException("ville could not be empty string");	
			}
		}else{
			throw new FieldFormatException("ville must be a string");
		}
	}
	function setCp($cp){
		if(is_string($cp)){
			
			if(str_replace(" ","",$cp) != ""){
				if(strlen($cp) > 0 and strlen($cp) < 21){
					$this->cp  =$cp;
				}else{
					throw new FieldFormatException("cp length could be 1 to 20 char");
				}
			}else{
				throw new FieldFormatException("cp could not be empty string");	
			}
		}else{
			throw new FieldFormatException("cp must be a string");
		}
	}
	function setBoite($boite){
		if(is_string($boite)){
			
			if(str_replace(" ","",$boite) != ""){
				if(strlen($boite) > 0 and strlen($boite) < 7){
					$this->boite  =$boite;
				}else{
					throw new FieldFormatException("boite length could be 1 to 6 char");
				}
			}else{
				throw new FieldFormatException("boite could not be empty string");	
			}
		}else{
			throw new FieldFormatException("boite must be a string");
		}
	}
	function setNumero($numero){
		if(is_string($numero)){
			
			if(str_replace(" ","",$numero) != ""){
				if(strlen($numero) > 0 and strlen($numero) < 7){
					$this->numero  =$numero;
				}else{
					throw new FieldFormatException("numero length could be 1 to 6 char");
				}
			}else{
				throw new FieldFormatException("numero could not be empty string");	
			}
		}else{
			throw new FieldFormatException("numero must be a string");
		}
	}
	function setRue($rue){
		if(is_string($rue)){
			
			if(str_replace(" ","",$rue) != ""){
				if(strlen($rue) > 0 and strlen($rue) < 61){
					$this->rue  =$rue;
				}else{
					throw new FieldFormatException("rue length could be 1 to 60 char");
				}
			}else{
				throw new FieldFormatException("rue could not be empty string");	
			}
		}else{
			throw new FieldFormatException("rue must be a string");
		}
	}
	function setEmail($email){
		if(Validator::validateEmail($email)){
				$this->email=$email;
		}else{
			throw new FieldFormatException("This is not an email adresse");
		}
	}
	function setPseudo($pseudo){
		if(is_string($pseudo)){
			if(str_replace(" ","",$pseudo) != ""){
				if(strlen($pseudo) > 0 and strlen($pseudo) < 16){
					$this->pseudo  =$pseudo;
				}else{
					throw new FieldFormatException("pseudo length could be 1 to 15 char");
				}
			}else{
				throw new FieldFormatException("pseudo could not be empty string");	
			}
		}else{
			throw new FieldFormatException("pseudo must be a string");
		}
	}
	function setPrenom($prenom){
		if(is_string($prenom)){
			
			if(str_replace(" ","",$prenom) != ""){
				if(strlen($prenom) > 0 and strlen($prenom) < 61){
					$this->prenom =$prenom;
				}else{
					throw new FieldFormatException("prenom length could be 1 to 60 char");
				}
			}else{
				throw new FieldFormatException("prenom could not be empty string");	
			}
		}else{
			throw new FieldFormatException("prenom must be a string");
		}
	}
	function setNom($nom){
		if(is_string($nom)){
			
			if(str_replace(" ","",$nom) != ""){
				if(strlen($nom) > 0 and strlen($nom) < 61){
					$this->nom =$nom;
				}else{
					throw new FieldFormatException("nom length could be 1 to 60 char");
				}
			}else{
				throw new FieldFormatException("nom could not be empty string");	
			}
		}else{
			throw new FieldFormatException("nom must be a string");
		}
	}
	function setLangue($Langue){
		
		if($Langue instanceof Langue){
			$this->Langue=$Langue;
		}else{
			throw new FieldFormatException("Langue must be an instance of Langue bean");
		}
	}
	function getProfile(){
		return $this->Profile;
	}
	function getId(){
		return $this->id;
	}
 	function getNom(){
		return $this->nom;
	}
	function getPrenom(){
		return $this->prenom;
	}
	function getPseudo(){
		return $this->pseudo;
	}
	function getEmail(){
		return $this->email;
	}
	function getRue(){
		return $this->rue;
	}
	function getNumero(){
		return $this->numero;
	}
	function getBoite(){
		return $this->boite;
	}
	function getCp(){
		return $this->cp;
	}
	function getVille(){
		return $this->ville;
	}
	function getPays(){
		return $this->pays;
	}
	function getLangue(){
		return $this->Langue;
	}
	function getIp(){
		return $this->ip;
	}
	function getDdn(){
		return $this->ddn;
	}
	function getCreated(){
		return $this->created;
	}
	function getLastConnection(){
		return $this->last_connected;
	}
	function getPwsHash(){
		return $this->pws_hash;
	}
 }
?>
